package servlet2;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//重定向
public class ResponseRedirectServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("曾到此一游");

        //----------------------请求重定向的方法一-------------------------
        /*
        //设置响应状态码302，表示重定向（已搬迁）
        response.setStatus(302);
        //设置响应头，说明 新的地址在哪里
        response.setHeader("location", "http://localhost:8080/05_Servlet/responseRedirect2");
        //response.setHeader("location", "http://localhost:8080/05_Servlet/WEB-INF/");不能访问WEB-INF下的资源
        */

        //----------------------请求重定向的方法二-------------------------
        response.sendRedirect("http://localhost:8080/05_Servlet/responseRedirect2");



        //保存变量
        request.setAttribute("key","value");
    }
}
